{
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "# Artificial Neural Network (ANN)"
      ],
      "metadata": {}
    },
    {
      "cell_type": "markdown",
      "source": [
        "Deep Neural Network (DNN) Regressor\n",
        "\n",
        "3 layers: 1) Input 2) Hidden and 3) Output\n",
        "\n",
        "feature: Input data to the network(features)\n",
        "\n",
        "label: output from the network (labels)\n",
        "\n",
        "loss function: Metric used to estimate the performance of the learning phase\n",
        "\n",
        "optimizer: Improve the learning by updating the knowledge in the network"
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "import numpy as np\n",
        "import matplotlib.pyplot as plt\n",
        "import pandas as pd\n",
        "\n",
        "import warnings\n",
        "warnings.filterwarnings(\"ignore\")\n",
        "\n",
        "# fix_yahoo_finance is used to fetch data \n",
        "import fix_yahoo_finance as yf\n",
        "yf.pdr_override()"
      ],
      "outputs": [],
      "execution_count": 1,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## (1) Import the data"
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "# input\n",
        "symbol = 'AMD'\n",
        "start = '2014-01-01'\n",
        "end = '2018-08-27'\n",
        "\n",
        "# Read data \n",
        "dataset = yf.download(symbol,start,end)\n",
        "\n",
        "# View Columns\n",
        "dataset.head()"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[*********************100%***********************]  1 of 1 downloaded\n"
          ]
        },
        {
          "output_type": "execute_result",
          "execution_count": 2,
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Open</th>\n",
              "      <th>High</th>\n",
              "      <th>Low</th>\n",
              "      <th>Close</th>\n",
              "      <th>Adj Close</th>\n",
              "      <th>Volume</th>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Date</th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>2014-01-02</th>\n",
              "      <td>3.85</td>\n",
              "      <td>3.98</td>\n",
              "      <td>3.84</td>\n",
              "      <td>3.95</td>\n",
              "      <td>3.95</td>\n",
              "      <td>20548400</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2014-01-03</th>\n",
              "      <td>3.98</td>\n",
              "      <td>4.00</td>\n",
              "      <td>3.88</td>\n",
              "      <td>4.00</td>\n",
              "      <td>4.00</td>\n",
              "      <td>22887200</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2014-01-06</th>\n",
              "      <td>4.01</td>\n",
              "      <td>4.18</td>\n",
              "      <td>3.99</td>\n",
              "      <td>4.13</td>\n",
              "      <td>4.13</td>\n",
              "      <td>42398300</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2014-01-07</th>\n",
              "      <td>4.19</td>\n",
              "      <td>4.25</td>\n",
              "      <td>4.11</td>\n",
              "      <td>4.18</td>\n",
              "      <td>4.18</td>\n",
              "      <td>42932100</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2014-01-08</th>\n",
              "      <td>4.23</td>\n",
              "      <td>4.26</td>\n",
              "      <td>4.14</td>\n",
              "      <td>4.18</td>\n",
              "      <td>4.18</td>\n",
              "      <td>30678700</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "            Open  High   Low  Close  Adj Close    Volume\n",
              "Date                                                    \n",
              "2014-01-02  3.85  3.98  3.84   3.95       3.95  20548400\n",
              "2014-01-03  3.98  4.00  3.88   4.00       4.00  22887200\n",
              "2014-01-06  4.01  4.18  3.99   4.13       4.13  42398300\n",
              "2014-01-07  4.19  4.25  4.11   4.18       4.18  42932100\n",
              "2014-01-08  4.23  4.26  4.14   4.18       4.18  30678700"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 2,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Create more data\n",
        "dataset['Increase_Decrease'] = np.where(dataset['Volume'].shift(-1) > dataset['Volume'],1,0)\n",
        "dataset['Buy_Sell_on_Open'] = np.where(dataset['Open'].shift(-1) > dataset['Open'],1,-1)\n",
        "dataset['Buy_Sell'] = np.where(dataset['Adj Close'].shift(-1) > dataset['Adj Close'],1,-1)\n",
        "dataset['Returns'] = dataset['Adj Close'].pct_change()\n",
        "dataset = dataset.dropna()\n",
        "dataset.head()"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 3,
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Open</th>\n",
              "      <th>High</th>\n",
              "      <th>Low</th>\n",
              "      <th>Close</th>\n",
              "      <th>Adj Close</th>\n",
              "      <th>Volume</th>\n",
              "      <th>Increase_Decrease</th>\n",
              "      <th>Buy_Sell_on_Open</th>\n",
              "      <th>Buy_Sell</th>\n",
              "      <th>Return</th>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Date</th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>2014-01-03</th>\n",
              "      <td>3.98</td>\n",
              "      <td>4.00</td>\n",
              "      <td>3.88</td>\n",
              "      <td>4.00</td>\n",
              "      <td>4.00</td>\n",
              "      <td>22887200</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>0.012658</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2014-01-06</th>\n",
              "      <td>4.01</td>\n",
              "      <td>4.18</td>\n",
              "      <td>3.99</td>\n",
              "      <td>4.13</td>\n",
              "      <td>4.13</td>\n",
              "      <td>42398300</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>0.032500</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2014-01-07</th>\n",
              "      <td>4.19</td>\n",
              "      <td>4.25</td>\n",
              "      <td>4.11</td>\n",
              "      <td>4.18</td>\n",
              "      <td>4.18</td>\n",
              "      <td>42932100</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>-1</td>\n",
              "      <td>0.012107</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2014-01-08</th>\n",
              "      <td>4.23</td>\n",
              "      <td>4.26</td>\n",
              "      <td>4.14</td>\n",
              "      <td>4.18</td>\n",
              "      <td>4.18</td>\n",
              "      <td>30678700</td>\n",
              "      <td>0</td>\n",
              "      <td>-1</td>\n",
              "      <td>-1</td>\n",
              "      <td>0.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2014-01-09</th>\n",
              "      <td>4.20</td>\n",
              "      <td>4.23</td>\n",
              "      <td>4.05</td>\n",
              "      <td>4.09</td>\n",
              "      <td>4.09</td>\n",
              "      <td>30667600</td>\n",
              "      <td>0</td>\n",
              "      <td>-1</td>\n",
              "      <td>1</td>\n",
              "      <td>-0.021531</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "            Open  High   Low  Close  Adj Close    Volume  Increase_Decrease  \\\n",
              "Date                                                                          \n",
              "2014-01-03  3.98  4.00  3.88   4.00       4.00  22887200                  1   \n",
              "2014-01-06  4.01  4.18  3.99   4.13       4.13  42398300                  1   \n",
              "2014-01-07  4.19  4.25  4.11   4.18       4.18  42932100                  0   \n",
              "2014-01-08  4.23  4.26  4.14   4.18       4.18  30678700                  0   \n",
              "2014-01-09  4.20  4.23  4.05   4.09       4.09  30667600                  0   \n",
              "\n",
              "            Buy_Sell_on_Open  Buy_Sell    Return  \n",
              "Date                                              \n",
              "2014-01-03                 1         1  0.012658  \n",
              "2014-01-06                 1         1  0.032500  \n",
              "2014-01-07                 1        -1  0.012107  \n",
              "2014-01-08                -1        -1  0.000000  \n",
              "2014-01-09                -1         1 -0.021531  "
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 3,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "dataset.shape"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 4,
          "data": {
            "text/plain": [
              "(1171, 10)"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 4,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "X = dataset.drop(['Adj Close', 'Close'], axis=1)  \n",
        "y = dataset['Adj Close'] "
      ],
      "outputs": [],
      "execution_count": 5,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "from sklearn.model_selection import train_test_split\n",
        "\n",
        "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
        "y_train  = y_train.astype(int)\n",
        "y_test  = y_test.astype(int)\n",
        "batch_size =len(X_train)\n",
        "\n",
        "print(X_train.shape, y_train.shape,y_test.shape)"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "(936, 8) (936,) (235,)\n"
          ]
        }
      ],
      "execution_count": 6,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## (2) Transform the data"
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "## rescale\n",
        "from sklearn.preprocessing import MinMaxScaler\n",
        "scaler = MinMaxScaler()\n",
        "# Train\n",
        "X_train_scaled = scaler.fit_transform(X_train.astype(np.float64))\n",
        "# test\n",
        "X_test_scaled = scaler.fit_transform(X_test.astype(np.float64))"
      ],
      "outputs": [],
      "execution_count": 7,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "print(X_train_scaled.shape, X_test_scaled.shape)"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "(936, 8) (235, 8)\n"
          ]
        }
      ],
      "execution_count": 28,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## (3) Construct the tensor"
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "import tensorflow as tf\n",
        "\n",
        "feature_columns = [tf.feature_column.numeric_column('x', shape=X_train_scaled.shape[1:])]\t\t"
      ],
      "outputs": [],
      "execution_count": 8,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## (4) Build the model"
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "estimator = tf.estimator.DNNRegressor(\n",
        "    feature_columns=feature_columns,\n",
        "    hidden_units=[300, 100])"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "INFO:tensorflow:Using default config.\n",
            "WARNING:tensorflow:Using temporary folder as model directory: C:\\Users\\TINHAN~1\\AppData\\Local\\Temp\\tmp40fu3k68\n",
            "INFO:tensorflow:Using config: {'_service': None, '_save_checkpoints_secs': 600, '_session_config': None, '_task_id': 0, '_log_step_count_steps': 100, '_is_chief': True, '_keep_checkpoint_max': 5, '_master': '', '_num_worker_replicas': 1, '_keep_checkpoint_every_n_hours': 10000, '_save_checkpoints_steps': None, '_evaluation_master': '', '_tf_random_seed': None, '_cluster_spec': <tensorflow.python.training.server_lib.ClusterSpec object at 0x0000029778509710>, '_task_type': 'worker', '_device_fn': None, '_num_ps_replicas': 0, '_model_dir': 'C:\\\\Users\\\\TINHAN~1\\\\AppData\\\\Local\\\\Temp\\\\tmp40fu3k68', '_global_id_in_cluster': 0, '_save_summary_steps': 100, '_train_distribute': None}\n"
          ]
        }
      ],
      "execution_count": 32,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## (5) Train and evaluate the model"
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "# Train the estimator\n",
        "train_input = tf.estimator.inputs.numpy_input_fn(\n",
        "    x={\"x\": X_train_scaled},\n",
        "    y=y_train,\n",
        "    batch_size=50,\n",
        "    shuffle=False,\n",
        "    num_epochs=None)\n",
        "estimator.train(input_fn = train_input,steps=1000) \n",
        "eval_input = tf.estimator.inputs.numpy_input_fn(\n",
        "    x={\"x\": X_test_scaled},\n",
        "    y=y_test, \n",
        "    shuffle=False,\n",
        "    batch_size=X_test_scaled.shape[0],\n",
        "    num_epochs=1)\n",
        "estimator.evaluate(eval_input,steps=None) "
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "INFO:tensorflow:Calling model_fn.\n",
            "INFO:tensorflow:Done calling model_fn.\n",
            "INFO:tensorflow:Create CheckpointSaverHook.\n",
            "INFO:tensorflow:Graph was finalized.\n",
            "INFO:tensorflow:Running local_init_op.\n",
            "INFO:tensorflow:Done running local_init_op.\n",
            "INFO:tensorflow:Saving checkpoints for 0 into C:\\Users\\TINHAN~1\\AppData\\Local\\Temp\\tmp40fu3k68\\model.ckpt.\n",
            "INFO:tensorflow:loss = 3834.94, step = 1\n",
            "INFO:tensorflow:global_step/sec: 680.489\n",
            "INFO:tensorflow:loss = 6.5443, step = 101 (0.149 sec)\n",
            "INFO:tensorflow:global_step/sec: 869.846\n",
            "INFO:tensorflow:loss = 5.31314, step = 201 (0.115 sec)\n",
            "INFO:tensorflow:global_step/sec: 806.707\n",
            "INFO:tensorflow:loss = 6.1748, step = 301 (0.124 sec)\n",
            "INFO:tensorflow:global_step/sec: 840.608\n",
            "INFO:tensorflow:loss = 4.62847, step = 401 (0.119 sec)\n",
            "INFO:tensorflow:global_step/sec: 800.255\n",
            "INFO:tensorflow:loss = 5.12176, step = 501 (0.134 sec)\n",
            "INFO:tensorflow:global_step/sec: 813.267\n",
            "INFO:tensorflow:loss = 5.35003, step = 601 (0.114 sec)\n",
            "INFO:tensorflow:global_step/sec: 775.443\n",
            "INFO:tensorflow:loss = 4.74212, step = 701 (0.130 sec)\n",
            "INFO:tensorflow:global_step/sec: 806.71\n",
            "INFO:tensorflow:loss = 5.41142, step = 801 (0.124 sec)\n",
            "INFO:tensorflow:global_step/sec: 813.267\n",
            "INFO:tensorflow:loss = 5.16857, step = 901 (0.122 sec)\n",
            "INFO:tensorflow:Saving checkpoints for 1000 into C:\\Users\\TINHAN~1\\AppData\\Local\\Temp\\tmp40fu3k68\\model.ckpt.\n",
            "INFO:tensorflow:Loss for final step: 4.42931.\n",
            "INFO:tensorflow:Calling model_fn.\n",
            "INFO:tensorflow:Done calling model_fn.\n",
            "INFO:tensorflow:Starting evaluation at 2019-01-14-02:46:54\n",
            "INFO:tensorflow:Graph was finalized.\n",
            "INFO:tensorflow:Restoring parameters from C:\\Users\\TINHAN~1\\AppData\\Local\\Temp\\tmp40fu3k68\\model.ckpt-1000\n",
            "INFO:tensorflow:Running local_init_op.\n",
            "INFO:tensorflow:Done running local_init_op.\n",
            "INFO:tensorflow:Finished evaluation at 2019-01-14-02:46:54\n",
            "INFO:tensorflow:Saving dict for global step 1000: average_loss = 6.49827, global_step = 1000, loss = 1527.09\n",
            "INFO:tensorflow:Saving 'checkpoint_path' summary for global step 1000: C:\\Users\\TINHAN~1\\AppData\\Local\\Temp\\tmp40fu3k68\\model.ckpt-1000\n"
          ]
        },
        {
          "output_type": "execute_result",
          "execution_count": 33,
          "data": {
            "text/plain": [
              "{'average_loss': 6.4982734, 'global_step': 1000, 'loss': 1527.0942}"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 33,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## (6) Improve the model"
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "estimator_imp = tf.estimator.DNNRegressor(\n",
        "    feature_columns=feature_columns,\n",
        "    hidden_units=[300, 100],\n",
        "    dropout=0.3,\n",
        "    optimizer=tf.train.ProximalAdagradOptimizer(\n",
        "      learning_rate=0.01,\n",
        "      l1_regularization_strength=0.01, \n",
        "      l2_regularization_strength=0.01\n",
        "    ))\n",
        "estimator_imp.train(input_fn = train_input,steps=1000) \n",
        "estimator_imp.evaluate(eval_input,steps=None) "
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "INFO:tensorflow:Using default config.\n",
            "WARNING:tensorflow:Using temporary folder as model directory: C:\\Users\\TINHAN~1\\AppData\\Local\\Temp\\tmpoan4nk2h\n",
            "INFO:tensorflow:Using config: {'_service': None, '_save_checkpoints_secs': 600, '_session_config': None, '_task_id': 0, '_log_step_count_steps': 100, '_is_chief': True, '_keep_checkpoint_max': 5, '_master': '', '_num_worker_replicas': 1, '_keep_checkpoint_every_n_hours': 10000, '_save_checkpoints_steps': None, '_evaluation_master': '', '_tf_random_seed': None, '_cluster_spec': <tensorflow.python.training.server_lib.ClusterSpec object at 0x0000029778EC56A0>, '_task_type': 'worker', '_device_fn': None, '_num_ps_replicas': 0, '_model_dir': 'C:\\\\Users\\\\TINHAN~1\\\\AppData\\\\Local\\\\Temp\\\\tmpoan4nk2h', '_global_id_in_cluster': 0, '_save_summary_steps': 100, '_train_distribute': None}\n",
            "INFO:tensorflow:Calling model_fn.\n",
            "INFO:tensorflow:Done calling model_fn.\n",
            "INFO:tensorflow:Create CheckpointSaverHook.\n",
            "INFO:tensorflow:Graph was finalized.\n",
            "INFO:tensorflow:Running local_init_op.\n",
            "INFO:tensorflow:Done running local_init_op.\n",
            "INFO:tensorflow:Saving checkpoints for 0 into C:\\Users\\TINHAN~1\\AppData\\Local\\Temp\\tmpoan4nk2h\\model.ckpt.\n",
            "INFO:tensorflow:loss = 3623.79, step = 1\n",
            "INFO:tensorflow:global_step/sec: 505.211\n",
            "INFO:tensorflow:loss = 57.7636, step = 101 (0.199 sec)\n",
            "INFO:tensorflow:global_step/sec: 598.995\n",
            "INFO:tensorflow:loss = 38.5281, step = 201 (0.167 sec)\n",
            "INFO:tensorflow:global_step/sec: 534.93\n",
            "INFO:tensorflow:loss = 46.048, step = 301 (0.187 sec)\n",
            "INFO:tensorflow:global_step/sec: 609.952\n",
            "INFO:tensorflow:loss = 47.9705, step = 401 (0.164 sec)\n",
            "INFO:tensorflow:global_step/sec: 694.667\n",
            "INFO:tensorflow:loss = 58.5349, step = 501 (0.144 sec)\n",
            "INFO:tensorflow:global_step/sec: 641.229\n",
            "INFO:tensorflow:loss = 29.0991, step = 601 (0.156 sec)\n",
            "INFO:tensorflow:global_step/sec: 658.106\n",
            "INFO:tensorflow:loss = 67.156, step = 701 (0.151 sec)\n",
            "INFO:tensorflow:global_step/sec: 666.88\n",
            "INFO:tensorflow:loss = 48.2238, step = 801 (0.151 sec)\n",
            "INFO:tensorflow:global_step/sec: 637.147\n",
            "INFO:tensorflow:loss = 59.5531, step = 901 (0.156 sec)\n",
            "INFO:tensorflow:Saving checkpoints for 1000 into C:\\Users\\TINHAN~1\\AppData\\Local\\Temp\\tmpoan4nk2h\\model.ckpt.\n",
            "INFO:tensorflow:Loss for final step: 56.8203.\n",
            "INFO:tensorflow:Calling model_fn.\n",
            "INFO:tensorflow:Done calling model_fn.\n",
            "INFO:tensorflow:Starting evaluation at 2019-01-14-02:47:32\n",
            "INFO:tensorflow:Graph was finalized.\n",
            "INFO:tensorflow:Restoring parameters from C:\\Users\\TINHAN~1\\AppData\\Local\\Temp\\tmpoan4nk2h\\model.ckpt-1000\n",
            "INFO:tensorflow:Running local_init_op.\n",
            "INFO:tensorflow:Done running local_init_op.\n",
            "INFO:tensorflow:Finished evaluation at 2019-01-14-02:47:32\n",
            "INFO:tensorflow:Saving dict for global step 1000: average_loss = 6.13989, global_step = 1000, loss = 1442.88\n",
            "INFO:tensorflow:Saving 'checkpoint_path' summary for global step 1000: C:\\Users\\TINHAN~1\\AppData\\Local\\Temp\\tmpoan4nk2h\\model.ckpt-1000\n"
          ]
        },
        {
          "output_type": "execute_result",
          "execution_count": 36,
          "data": {
            "text/plain": [
              "{'average_loss': 6.139895, 'global_step': 1000, 'loss': 1442.8754}"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 36,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    }
  ],
  "metadata": {
    "kernel_info": {
      "name": "python3"
    },
    "language_info": {
      "version": "3.5.5",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "codemirror_mode": {
        "version": 3,
        "name": "ipython"
      },
      "mimetype": "text/x-python",
      "file_extension": ".py",
      "name": "python"
    },
    "kernelspec": {
      "name": "python3",
      "language": "python",
      "display_name": "Python 3"
    },
    "nteract": {
      "version": "0.15.0"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 4
}